<?php require 'db.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
    <link href="css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
    <header>
        <h3 class="muted">Admin Panel</h3>
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container">
                    <ul class="nav">
                        <li>
                            <a href="index.php">Home</a>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Projects <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="projects.php">View</a></li>
                                <li><a href="project.php">Add Project</a></li>
                            </ul>
                        </li>
                        <li class="dropdown active">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Architects <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="architects.html">View</a></li>
                                <li><a href="architect.php">Add Architect</a></li>
                            </ul>
                        </li>
                        <li>
                            <a href="#">Settings</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </header>
    <section>
        <ul class="breadcrumb">
            <li><a href="index.php">Home</a> <span class="divider">/</span></li>
            <li class="active">Architects</li>
        </ul>
        <form action="architect.php" data-action="architect.php" method="get">
            <input name="action" value="add"  type="hidden" />
        <div class="text-right">
            <button type="submit" id="add" class="btn btn-primary">Add</button>
            <button type="submit" id="edit" class="btn btn-primary">Edit</button>
            <button type="submit" id="delete" class="btn btn-danger">Delete</button>
            <hr />
        </div>
        <div class="row-fluid">
            <div class="span8">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Info</th>
                        <th>Price</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                        if(is_numeric($_GET['id'])) $id = intval($_GET['id']);

                        $result = mysqli_query($con, "SELECT * FROM architects");

                        $count = 0;

                        while($row = mysqli_fetch_assoc($result))
                        {
                            $count++;
                            ?>
                            <tr <?php if($id == $row['id']) echo 'class="active"'; ?> >
                                <td>
                                    <label class="checkbox">
                                        <input name="id[]" value="<?php echo $row['id']; ?>" type="checkbox" />
                                        <?php echo $count; ?>
                                    </label>
                                </td>
                                <td><a href="<?php echo 'architects.php?id='.$row['id']; ?>"><?php echo $row['name']; ?></a></td>
                                <td><?php echo $row['info']; ?></td>
                                <td><?php echo $row['price']; ?> per hour</td>
                            </tr>
                    <?php }
                    ?>
                    </tbody>
                </table>
            </div>
            <div class="span4">
                <?php
                    if($id > -1){
                        $result = mysqli_query($con, "SELECT * FROM architects WHERE id = ".$id);
                        $architect = mysqli_fetch_assoc($result);
                ?>
                <h4><?php echo $architect['name']; ?>'s Projects</h4>
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#active" data-toggle="pill">Active</a></li>
                    <li><a href="#done" data-toggle="pill">Done</a></li>
                </ul>
                <div class="tab-content">

                    <div class="tab-pane active" id="active">
                        <ul>
                            <?php
                                $result = mysqli_query($con, "SELECT * FROM projects WHERE architect_id = ".$id." AND (finish_date > CURDATE() OR finish_date IS NULL)");
                                while($row = mysqli_fetch_assoc($result)){ ?>
                                <li>
                                    <a class="btn-link" href="project.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
                                </li>
                            <?php } ?>
                        </ul>
                    </div>
                    <div class="tab-pane" id="done">
                        <ul>
                            <?php
                            $result = mysqli_query($con, "SELECT * FROM projects WHERE architect_id = ".$id." AND finish_date <= CURDATE()");
                            while($row = mysqli_fetch_assoc($result)){ ?>
                                <li>
                                    <a class="btn-link" href="project.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
                                </li>
                            <?php } ?>
                        </ul>
                    </div>
                </div>
                <?php } ?>
            </div>
        </div>
        <!--
        <hr />

        <div class="pagination">
            <ul>
                <li><a href="#">Prev</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li><a href="#">Next</a></li>
            </ul>
        </div>
        //-->

        </form>
    </section>
    <footer>
        <hr />
        <p>&copy; Company 2013</p>
    </footer>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/default.js"></script>
</body>
</html>